package com.cg.controller;

import com.cg.client.SystemClient;
import com.cg.dto.NoticeDepartmentDto;
import com.cg.dto.NoticePageDto;
import com.cg.dto.Result;
import com.cg.utils.TokenUtil;
import com.cg.vo.QueryNoticeByNoticeIdVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @ClassName NoticeController
 * @Description TODO
 * @Author CG
 * @Date 2023/12/16 9:30
 **/
@RestController
@RequestMapping("/notice")
public class NoticeController {

    @Resource
    private SystemClient systemClient;

    /**
     * 查询公告信息
     */
    @PostMapping("/noticeList")
    Result<Map<String,Object>> noticeList(NoticePageDto noticePageDto){
        return systemClient.noticeList(noticePageDto);
    }

    /**
     * 新增公告信息
     */
    @PostMapping("/createNotice")
    public Result createNotice(HttpServletRequest request, @RequestBody NoticeDepartmentDto noticeDepartmentDto){
        String token = request.getHeader("token");
        //获取用户id
        Integer userId = TokenUtil.getUserIdByToken(token);
        noticeDepartmentDto.setCreateUser(userId);
        return systemClient.createNotice(noticeDepartmentDto);
    }


    /**
     * 根据部门id查询部门详细信息
     */
    @PostMapping("/queryNotice")
    public Result<QueryNoticeByNoticeIdVo> queryNotice(Integer id){
        return systemClient.queryNotice(id);
    }


    /**
     * 删除公告信息
     */
    @PostMapping("/deleteNoticeById")
    public Result deleteNoticeById(Integer noticeId){
        return systemClient.deleteNoticeById(noticeId);
    }



    /**
     * 修改公告信息
     */
    @PostMapping("/setNotice")
    public Result setNotice(@RequestBody NoticeDepartmentDto noticeDepartmentDto){
        return systemClient.setNotice(noticeDepartmentDto);
    }
}
